package org.dru.clay.respository.ivy;

import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.dru.clay.respository.Configuration;
import org.dru.clay.respository.ResolveResult;
import org.dru.clay.respository.artifact.Artifact;
import org.dru.clay.respository.artifact.Module;
import org.dru.clay.respository.dependency.Dependency;

public class IvyXml implements ResolveResult {
	private final Module module;
	private final IvyStatus status;
	private final Map<String, Configuration> configurations;
	private final Set<Dependency> dependencies;

	public IvyXml(Module module, IvyStatus status, Map<String, Configuration> configurations, Set<Dependency> dependencies) {
		this.module = module;
		this.status = status;
		this.configurations = configurations;
		this.dependencies = dependencies;
	}

	@Override
	public Module getModule() {
		return module;
	}

	@Override
	public Set<Configuration> getConfigurations() {
		return new TreeSet<Configuration>(configurations.values());
	}

	@Override
	public Set<Dependency> getDependencies() {
		return dependencies;
	}

	@Override
	public String toString() {
		final StringBuilder builder = new StringBuilder("IvyXml:\n");
		builder.append("Plugin: ").append(module).append('\n');
		builder.append("Status: ").append(status).append('\n');

		builder.append("Configuration:\n");
		for (Configuration config : configurations.values()) {
			builder.append("  ").append(config.getName()).append('\n');
			for (Artifact artifact : config.getArtifacts()) {
				builder.append("    ").append(artifact).append('\n');
			}
		}

		builder.append("Dependencies:\n");
		for (Dependency dependency : dependencies) {
			builder.append("  ").append(dependency).append('\n');
		}

		return builder.toString();
	}
}
